import globals from "globals"
import pluginJs from "@eslint/js"
import tseslint from "typescript-eslint"
import pluginVue from "eslint-plugin-vue"
import prettierRecommended from "eslint-plugin-prettier/recommended"
// 1.
// import autoImport from "./.eslintrc-auto-import.json" with { type: "json" }

// 2.避免自动导入vue api报错
import { createRequire } from "module"
const require = createRequire(import.meta.url)
const autoImport = require("./.eslintrc-auto-import.json")

export default [
  { files: ["**/*.{js,mjs,cjs,ts,vue}"] }, // 1.检测⽂件的格式
  {
    languageOptions: {
      globals: { ...globals.browser, ...globals.node, ...autoImport.globals }
    }
  }, // 2.定义不同环境的全局变量
  pluginJs.configs.recommended,
  ...tseslint.configs.recommended,
  ...pluginVue.configs["flat/essential"], //js ts、vue推荐规则
  {
    files: ["**/*.vue"],
    languageOptions: { parserOptions: { parser: tseslint.parser } }
  },
  {
    // 自定义规则,根据需要增加  eslint 主要是校验代码规范  prettier  格式化代码的
    rules: {
      "no-console": "warn",
      "vue/multi-word-component-names": "off", // 不要求Vue 组件的名字必须是多词形式。
      //  "semi": ["error", "always"] // 强制分号
      "@typescript-eslint/no-explicit-any": "off" // 关闭any类型的警告
    }
  },
  prettierRecommended // 覆盖掉eslint的规范
]
